from django.db import models

# 导入时间域
from django.utils import timezone


# 基类
class Base(models.Model):
    # 创建时间
    create_time = models.DateTimeField(default=timezone.now, null=True)

    class Meta:
        abstract = True


# 用户类
class User(Base):
    gender = {
        ('1', '男'),
        ('2', '女')
    }
    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=200)
    phone = models.CharField(max_length=11)
    gender = models.CharField(max_length=10, choices=gender)
    num = models.IntegerField(null=True)
    email = models.CharField(max_length=128)
    image = models.ImageField(upload_to='static/upload', null=True)

    class Meta:
        db_table = "user"


class Permission(models.Model):
    permission_name = models.CharField(max_length=30)

    class Meta:
        db_table = 'permissions'


class Access(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    permission = models.ForeignKey(Permission, on_delete=models.CASCADE)

    class Meta:
        db_table = 'access'


class Course(Base):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=100, null=True)
    desc = models.CharField(max_length=200, null=True)
    price = models.IntegerField(null=True)
    cid = models.IntegerField(null=True)
    video = models.CharField(max_length=100, null=True)

    class Meta:
        db_table = 'course'